"""
封装处理不同解析文件的方法
"""
import json
from openpyxl import load_workbook
def parse_from_json(filepath):
    data = json.load(open('data/topics.json', mode='r', encoding='utf8'))
    testdata = data["test_data"]
    return testdata

def parse_from_excel(filepath,sheetname="Sheet1"):
    #加载Excel文件
    wb = load_workbook(filename=filepath)
    # 打印workbook中所有的sheet
    # print(wb.worksheets)
    # 加载worksheet
    ws = wb[sheetname]
    # print(ws['B'].value)
    test_data = []

    for x in range(2, len(tuple(ws.rows)) + 1):
        testcase_data = []
        for y in range(2, 7):
            testcase_data.append(ws.cell(row=x, column=y).value)
            print(ws.cell(row=x, column=y).value, type(ws.cell(row=x, column=y).value))
        test_data.append(testcase_data)
    return test_data
